/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package simhya.model.store.faststore;

import simhya.model.store.Function;
import java.util.ArrayList;
import simhya.matheval.SymbolArray;
import simhya.model.store.Store;

/**
 *
 * @author Luca
 */
public class ConstantIncrementFunction implements Function {
    private double increment;
    private int var;
    private SymbolArray variablesArray;
    private double[] variables;

    public ConstantIncrementFunction(Store store, int varID, double inc) {
        this.variablesArray = (SymbolArray)store.getVariablesReference();
        this.var = varID;
        this.increment = inc;
        store.addExternalFunction(this);
    }

     public void initialize() {
        this.variables = variablesArray.getReferenceToValuesArray();
    }

    public double compute() {
        return variables[var] + increment;
//        return variablesArray.getValue(var) + increment;

    }

    public double compute(SymbolArray vars) {
        return vars.getValue(var) + increment;
//        return vars.getValue(var) + increment;
    }

     public double computeCache() {
        return variables[var] + increment;
//        return variablesArray.getValue(var) + increment;

    }

    public double computeCache(SymbolArray vars) {
        return vars.getValue(var) + increment;
//        return vars.getValue(var) + increment;
    }

    public ArrayList<Integer> getVariableList() {
        ArrayList<Integer> list = new ArrayList();
        list.add(var);
        return list;
    }

    public String toModelLanguage() {
        if (increment >= 0)
            return this.variablesArray.getName(var) + " += " + this.increment;
        else
            return this.variablesArray.getName(var) + " -= " + (-this.increment);
    }

    public double getConstantIncrement() {
        return increment;
    }

    public boolean isConstantIncrementFunction() {
        return true;
    }

    

}
